using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;


namespace CUSTOMS.Modules.QLHS.Components.QLBB
{
	public partial class BienBan
	{
		#region Private members.
		
		protected int _SoToKhai;
		protected string _MaHaiQuan = string.Empty;
		protected string _MaLoaiHinh = string.Empty;
		protected int _NamDangKy;
		protected string _MaDoanhNghiep = string.Empty;
		protected int _PhanLuong;
		protected int _SoTo;
		protected string _TruongHop = string.Empty;
		protected string _MaHaiQuanChuyenDen = string.Empty;
		protected string _NoiGiao = string.Empty;
		protected string _NguoiGiao = string.Empty;
		protected string _NoiNhan = string.Empty;
		protected string _NguoiNhan = string.Empty;
		protected DateTime _NgayBanGiao = new DateTime(1753, 1, 1);
		protected string _CanBoTheoDoi = string.Empty;
		protected string _TrangThai = string.Empty;
		protected string _GhiChu = string.Empty;
		protected string _SoBienBan = string.Empty;
		protected string _SoVanTaiDon = string.Empty;
		protected int _SoBanChinhToKhai;
		protected int _SoBanChinhDonChuyenCuaKhau;
		protected int _SoBanSaoVanTaiDon;
		protected int _SoBanChinhBanKeChiTiet;
		protected string _MoTaHangHoa = string.Empty;
		protected string _TinhTrangHangHoa = string.Empty;
		protected string _BienBanVeTinhTrangHangHoa = string.Empty;
		protected string _TuyenDuongVanChuyen = string.Empty;
		protected decimal _ChieuDai;
		protected decimal _ThoiGianVanChuyen;
		protected DateTime _GioXuatPhat = new DateTime(1753, 1, 1);
		protected string _CacVanDeLienQuan = string.Empty;
		protected string _NguoiNhapDuLieu = string.Empty;
		protected DateTime _NgayNhapDuLieu = new DateTime(1753, 1, 1);

		#endregion
		
		//---------------------------------------------------------------------------------------------

		#region Properties.
		
		public int SoToKhai
		{
			set {this._SoToKhai = value;}
			get {return this._SoToKhai;}
		}
		
		public string MaHaiQuan
		{
			set {this._MaHaiQuan = value;}
			get {return this._MaHaiQuan;}
		}
		
		public string MaLoaiHinh
		{
			set {this._MaLoaiHinh = value;}
			get {return this._MaLoaiHinh;}
		}
		
		public int NamDangKy
		{
			set {this._NamDangKy = value;}
			get {return this._NamDangKy;}
		}
		
		public string MaDoanhNghiep
		{
			set {this._MaDoanhNghiep = value;}
			get {return this._MaDoanhNghiep;}
		}
		
		public int PhanLuong
		{
			set {this._PhanLuong = value;}
			get {return this._PhanLuong;}
		}
		
		public int SoTo
		{
			set {this._SoTo = value;}
			get {return this._SoTo;}
		}
		
		public string TruongHop
		{
			set {this._TruongHop = value;}
			get {return this._TruongHop;}
		}
		
		public string MaHaiQuanChuyenDen
		{
			set {this._MaHaiQuanChuyenDen = value;}
			get {return this._MaHaiQuanChuyenDen;}
		}
		
		public string NoiGiao
		{
			set {this._NoiGiao = value;}
			get {return this._NoiGiao;}
		}
		
		public string NguoiGiao
		{
			set {this._NguoiGiao = value;}
			get {return this._NguoiGiao;}
		}
		
		public string NoiNhan
		{
			set {this._NoiNhan = value;}
			get {return this._NoiNhan;}
		}
		
		public string NguoiNhan
		{
			set {this._NguoiNhan = value;}
			get {return this._NguoiNhan;}
		}
		
		public DateTime NgayBanGiao
		{
			set {this._NgayBanGiao = value;}
			get {return this._NgayBanGiao;}
		}
		
		public string CanBoTheoDoi
		{
			set {this._CanBoTheoDoi = value;}
			get {return this._CanBoTheoDoi;}
		}
		
		public string TrangThai
		{
			set {this._TrangThai = value;}
			get {return this._TrangThai;}
		}
		
		public string GhiChu
		{
			set {this._GhiChu = value;}
			get {return this._GhiChu;}
		}
		
		public string SoBienBan
		{
			set {this._SoBienBan = value;}
			get {return this._SoBienBan;}
		}
		
		public string SoVanTaiDon
		{
			set {this._SoVanTaiDon = value;}
			get {return this._SoVanTaiDon;}
		}
		
		public int SoBanChinhToKhai
		{
			set {this._SoBanChinhToKhai = value;}
			get {return this._SoBanChinhToKhai;}
		}
		
		public int SoBanChinhDonChuyenCuaKhau
		{
			set {this._SoBanChinhDonChuyenCuaKhau = value;}
			get {return this._SoBanChinhDonChuyenCuaKhau;}
		}
		
		public int SoBanSaoVanTaiDon
		{
			set {this._SoBanSaoVanTaiDon = value;}
			get {return this._SoBanSaoVanTaiDon;}
		}
		
		public int SoBanChinhBanKeChiTiet
		{
			set {this._SoBanChinhBanKeChiTiet = value;}
			get {return this._SoBanChinhBanKeChiTiet;}
		}
		
		public string MoTaHangHoa
		{
			set {this._MoTaHangHoa = value;}
			get {return this._MoTaHangHoa;}
		}
		
		public string TinhTrangHangHoa
		{
			set {this._TinhTrangHangHoa = value;}
			get {return this._TinhTrangHangHoa;}
		}
		
		public string BienBanVeTinhTrangHangHoa
		{
			set {this._BienBanVeTinhTrangHangHoa = value;}
			get {return this._BienBanVeTinhTrangHangHoa;}
		}
		
		public string TuyenDuongVanChuyen
		{
			set {this._TuyenDuongVanChuyen = value;}
			get {return this._TuyenDuongVanChuyen;}
		}
		
		public decimal ChieuDai
		{
			set {this._ChieuDai = value;}
			get {return this._ChieuDai;}
		}
		
		public decimal ThoiGianVanChuyen
		{
			set {this._ThoiGianVanChuyen = value;}
			get {return this._ThoiGianVanChuyen;}
		}
		
		public DateTime GioXuatPhat
		{
			set {this._GioXuatPhat = value;}
			get {return this._GioXuatPhat;}
		}
		
		public string CacVanDeLienQuan
		{
			set {this._CacVanDeLienQuan = value;}
			get {return this._CacVanDeLienQuan;}
		}
		
		public string NguoiNhapDuLieu
		{
			set {this._NguoiNhapDuLieu = value;}
			get {return this._NguoiNhapDuLieu;}
		}
		
		public DateTime NgayNhapDuLieu
		{
			set {this._NgayNhapDuLieu = value;}
			get {return this._NgayNhapDuLieu;}
		}
		
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Select methods.
		
		public static BienBan Load(int soToKhai, string maHaiQuan, string maLoaiHinh, int namDangKy)
		{
			const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_Load]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@SoToKhai", SqlDbType.Int, soToKhai);
			db.AddInParameter(dbCommand, "@MaHaiQuan", SqlDbType.Char, maHaiQuan);
			db.AddInParameter(dbCommand, "@MaLoaiHinh", SqlDbType.Char, maLoaiHinh);
			db.AddInParameter(dbCommand, "@NamDangKy", SqlDbType.Int, namDangKy);
			BienBan entity = null;
            IDataReader reader = db.ExecuteReader(dbCommand);
			if (reader.Read())
			{
				entity = new BienBan();
				if (!reader.IsDBNull(reader.GetOrdinal("SoToKhai"))) entity.SoToKhai = reader.GetInt32(reader.GetOrdinal("SoToKhai"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaHaiQuan"))) entity.MaHaiQuan = reader.GetString(reader.GetOrdinal("MaHaiQuan"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaLoaiHinh"))) entity.MaLoaiHinh = reader.GetString(reader.GetOrdinal("MaLoaiHinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("NamDangKy"))) entity.NamDangKy = reader.GetInt32(reader.GetOrdinal("NamDangKy"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaDoanhNghiep"))) entity.MaDoanhNghiep = reader.GetString(reader.GetOrdinal("MaDoanhNghiep"));
				if (!reader.IsDBNull(reader.GetOrdinal("PhanLuong"))) entity.PhanLuong = reader.GetInt32(reader.GetOrdinal("PhanLuong"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoTo"))) entity.SoTo = reader.GetInt32(reader.GetOrdinal("SoTo"));
				if (!reader.IsDBNull(reader.GetOrdinal("TruongHop"))) entity.TruongHop = reader.GetString(reader.GetOrdinal("TruongHop"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaHaiQuanChuyenDen"))) entity.MaHaiQuanChuyenDen = reader.GetString(reader.GetOrdinal("MaHaiQuanChuyenDen"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiGiao"))) entity.NoiGiao = reader.GetString(reader.GetOrdinal("NoiGiao"));
				if (!reader.IsDBNull(reader.GetOrdinal("NguoiGiao"))) entity.NguoiGiao = reader.GetString(reader.GetOrdinal("NguoiGiao"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiNhan"))) entity.NoiNhan = reader.GetString(reader.GetOrdinal("NoiNhan"));
				if (!reader.IsDBNull(reader.GetOrdinal("NguoiNhan"))) entity.NguoiNhan = reader.GetString(reader.GetOrdinal("NguoiNhan"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayBanGiao"))) entity.NgayBanGiao = reader.GetDateTime(reader.GetOrdinal("NgayBanGiao"));
				if (!reader.IsDBNull(reader.GetOrdinal("CanBoTheoDoi"))) entity.CanBoTheoDoi = reader.GetString(reader.GetOrdinal("CanBoTheoDoi"));
				if (!reader.IsDBNull(reader.GetOrdinal("TrangThai"))) entity.TrangThai = reader.GetString(reader.GetOrdinal("TrangThai"));
				if (!reader.IsDBNull(reader.GetOrdinal("GhiChu"))) entity.GhiChu = reader.GetString(reader.GetOrdinal("GhiChu"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBienBan"))) entity.SoBienBan = reader.GetString(reader.GetOrdinal("SoBienBan"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoVanTaiDon"))) entity.SoVanTaiDon = reader.GetString(reader.GetOrdinal("SoVanTaiDon"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanChinhToKhai"))) entity.SoBanChinhToKhai = reader.GetInt32(reader.GetOrdinal("SoBanChinhToKhai"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanChinhDonChuyenCuaKhau"))) entity.SoBanChinhDonChuyenCuaKhau = reader.GetInt32(reader.GetOrdinal("SoBanChinhDonChuyenCuaKhau"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanSaoVanTaiDon"))) entity.SoBanSaoVanTaiDon = reader.GetInt32(reader.GetOrdinal("SoBanSaoVanTaiDon"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanChinhBanKeChiTiet"))) entity.SoBanChinhBanKeChiTiet = reader.GetInt32(reader.GetOrdinal("SoBanChinhBanKeChiTiet"));
				if (!reader.IsDBNull(reader.GetOrdinal("MoTaHangHoa"))) entity.MoTaHangHoa = reader.GetString(reader.GetOrdinal("MoTaHangHoa"));
				if (!reader.IsDBNull(reader.GetOrdinal("TinhTrangHangHoa"))) entity.TinhTrangHangHoa = reader.GetString(reader.GetOrdinal("TinhTrangHangHoa"));
				if (!reader.IsDBNull(reader.GetOrdinal("BienBanVeTinhTrangHangHoa"))) entity.BienBanVeTinhTrangHangHoa = reader.GetString(reader.GetOrdinal("BienBanVeTinhTrangHangHoa"));
				if (!reader.IsDBNull(reader.GetOrdinal("TuyenDuongVanChuyen"))) entity.TuyenDuongVanChuyen = reader.GetString(reader.GetOrdinal("TuyenDuongVanChuyen"));
				if (!reader.IsDBNull(reader.GetOrdinal("ChieuDai"))) entity.ChieuDai = reader.GetDecimal(reader.GetOrdinal("ChieuDai"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThoiGianVanChuyen"))) entity.ThoiGianVanChuyen = reader.GetDecimal(reader.GetOrdinal("ThoiGianVanChuyen"));
				if (!reader.IsDBNull(reader.GetOrdinal("GioXuatPhat"))) entity.GioXuatPhat = reader.GetDateTime(reader.GetOrdinal("GioXuatPhat"));
				if (!reader.IsDBNull(reader.GetOrdinal("CacVanDeLienQuan"))) entity.CacVanDeLienQuan = reader.GetString(reader.GetOrdinal("CacVanDeLienQuan"));
				if (!reader.IsDBNull(reader.GetOrdinal("NguoiNhapDuLieu"))) entity.NguoiNhapDuLieu = reader.GetString(reader.GetOrdinal("NguoiNhapDuLieu"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayNhapDuLieu"))) entity.NgayNhapDuLieu = reader.GetDateTime(reader.GetOrdinal("NgayNhapDuLieu"));
			}
			reader.Close();
			return entity;
		}		
		
		//---------------------------------------------------------------------------------------------
		public static IList<BienBan> SelectCollectionAll()
		{
			IList<BienBan> collection = new List<BienBan>();
			IDataReader reader = SelectReaderAll();
			while (reader.Read())
			{
				BienBan entity = new BienBan();
				
				if (!reader.IsDBNull(reader.GetOrdinal("SoToKhai"))) entity.SoToKhai = reader.GetInt32(reader.GetOrdinal("SoToKhai"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaHaiQuan"))) entity.MaHaiQuan = reader.GetString(reader.GetOrdinal("MaHaiQuan"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaLoaiHinh"))) entity.MaLoaiHinh = reader.GetString(reader.GetOrdinal("MaLoaiHinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("NamDangKy"))) entity.NamDangKy = reader.GetInt32(reader.GetOrdinal("NamDangKy"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaDoanhNghiep"))) entity.MaDoanhNghiep = reader.GetString(reader.GetOrdinal("MaDoanhNghiep"));
				if (!reader.IsDBNull(reader.GetOrdinal("PhanLuong"))) entity.PhanLuong = reader.GetInt32(reader.GetOrdinal("PhanLuong"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoTo"))) entity.SoTo = reader.GetInt32(reader.GetOrdinal("SoTo"));
				if (!reader.IsDBNull(reader.GetOrdinal("TruongHop"))) entity.TruongHop = reader.GetString(reader.GetOrdinal("TruongHop"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaHaiQuanChuyenDen"))) entity.MaHaiQuanChuyenDen = reader.GetString(reader.GetOrdinal("MaHaiQuanChuyenDen"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiGiao"))) entity.NoiGiao = reader.GetString(reader.GetOrdinal("NoiGiao"));
				if (!reader.IsDBNull(reader.GetOrdinal("NguoiGiao"))) entity.NguoiGiao = reader.GetString(reader.GetOrdinal("NguoiGiao"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiNhan"))) entity.NoiNhan = reader.GetString(reader.GetOrdinal("NoiNhan"));
				if (!reader.IsDBNull(reader.GetOrdinal("NguoiNhan"))) entity.NguoiNhan = reader.GetString(reader.GetOrdinal("NguoiNhan"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayBanGiao"))) entity.NgayBanGiao = reader.GetDateTime(reader.GetOrdinal("NgayBanGiao"));
				if (!reader.IsDBNull(reader.GetOrdinal("CanBoTheoDoi"))) entity.CanBoTheoDoi = reader.GetString(reader.GetOrdinal("CanBoTheoDoi"));
				if (!reader.IsDBNull(reader.GetOrdinal("TrangThai"))) entity.TrangThai = reader.GetString(reader.GetOrdinal("TrangThai"));
				if (!reader.IsDBNull(reader.GetOrdinal("GhiChu"))) entity.GhiChu = reader.GetString(reader.GetOrdinal("GhiChu"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBienBan"))) entity.SoBienBan = reader.GetString(reader.GetOrdinal("SoBienBan"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoVanTaiDon"))) entity.SoVanTaiDon = reader.GetString(reader.GetOrdinal("SoVanTaiDon"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanChinhToKhai"))) entity.SoBanChinhToKhai = reader.GetInt32(reader.GetOrdinal("SoBanChinhToKhai"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanChinhDonChuyenCuaKhau"))) entity.SoBanChinhDonChuyenCuaKhau = reader.GetInt32(reader.GetOrdinal("SoBanChinhDonChuyenCuaKhau"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanSaoVanTaiDon"))) entity.SoBanSaoVanTaiDon = reader.GetInt32(reader.GetOrdinal("SoBanSaoVanTaiDon"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanChinhBanKeChiTiet"))) entity.SoBanChinhBanKeChiTiet = reader.GetInt32(reader.GetOrdinal("SoBanChinhBanKeChiTiet"));
				if (!reader.IsDBNull(reader.GetOrdinal("MoTaHangHoa"))) entity.MoTaHangHoa = reader.GetString(reader.GetOrdinal("MoTaHangHoa"));
				if (!reader.IsDBNull(reader.GetOrdinal("TinhTrangHangHoa"))) entity.TinhTrangHangHoa = reader.GetString(reader.GetOrdinal("TinhTrangHangHoa"));
				if (!reader.IsDBNull(reader.GetOrdinal("BienBanVeTinhTrangHangHoa"))) entity.BienBanVeTinhTrangHangHoa = reader.GetString(reader.GetOrdinal("BienBanVeTinhTrangHangHoa"));
				if (!reader.IsDBNull(reader.GetOrdinal("TuyenDuongVanChuyen"))) entity.TuyenDuongVanChuyen = reader.GetString(reader.GetOrdinal("TuyenDuongVanChuyen"));
				if (!reader.IsDBNull(reader.GetOrdinal("ChieuDai"))) entity.ChieuDai = reader.GetDecimal(reader.GetOrdinal("ChieuDai"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThoiGianVanChuyen"))) entity.ThoiGianVanChuyen = reader.GetDecimal(reader.GetOrdinal("ThoiGianVanChuyen"));
				if (!reader.IsDBNull(reader.GetOrdinal("GioXuatPhat"))) entity.GioXuatPhat = reader.GetDateTime(reader.GetOrdinal("GioXuatPhat"));
				if (!reader.IsDBNull(reader.GetOrdinal("CacVanDeLienQuan"))) entity.CacVanDeLienQuan = reader.GetString(reader.GetOrdinal("CacVanDeLienQuan"));
				if (!reader.IsDBNull(reader.GetOrdinal("NguoiNhapDuLieu"))) entity.NguoiNhapDuLieu = reader.GetString(reader.GetOrdinal("NguoiNhapDuLieu"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayNhapDuLieu"))) entity.NgayNhapDuLieu = reader.GetDateTime(reader.GetOrdinal("NgayNhapDuLieu"));
				collection.Add(entity);
			}
			
			reader.Close();
			return collection;			
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public static IList<BienBan> SelectCollectionDynamic(string whereCondition, string orderByExpression)
		{
			IList<BienBan> collection = new List<BienBan>();

			IDataReader reader = SelectReaderDynamic(whereCondition, orderByExpression);
			while (reader.Read())
			{
				BienBan entity = new BienBan();
				
				if (!reader.IsDBNull(reader.GetOrdinal("SoToKhai"))) entity.SoToKhai = reader.GetInt32(reader.GetOrdinal("SoToKhai"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaHaiQuan"))) entity.MaHaiQuan = reader.GetString(reader.GetOrdinal("MaHaiQuan"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaLoaiHinh"))) entity.MaLoaiHinh = reader.GetString(reader.GetOrdinal("MaLoaiHinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("NamDangKy"))) entity.NamDangKy = reader.GetInt32(reader.GetOrdinal("NamDangKy"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaDoanhNghiep"))) entity.MaDoanhNghiep = reader.GetString(reader.GetOrdinal("MaDoanhNghiep"));
				if (!reader.IsDBNull(reader.GetOrdinal("PhanLuong"))) entity.PhanLuong = reader.GetInt32(reader.GetOrdinal("PhanLuong"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoTo"))) entity.SoTo = reader.GetInt32(reader.GetOrdinal("SoTo"));
				if (!reader.IsDBNull(reader.GetOrdinal("TruongHop"))) entity.TruongHop = reader.GetString(reader.GetOrdinal("TruongHop"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaHaiQuanChuyenDen"))) entity.MaHaiQuanChuyenDen = reader.GetString(reader.GetOrdinal("MaHaiQuanChuyenDen"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiGiao"))) entity.NoiGiao = reader.GetString(reader.GetOrdinal("NoiGiao"));
				if (!reader.IsDBNull(reader.GetOrdinal("NguoiGiao"))) entity.NguoiGiao = reader.GetString(reader.GetOrdinal("NguoiGiao"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiNhan"))) entity.NoiNhan = reader.GetString(reader.GetOrdinal("NoiNhan"));
				if (!reader.IsDBNull(reader.GetOrdinal("NguoiNhan"))) entity.NguoiNhan = reader.GetString(reader.GetOrdinal("NguoiNhan"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayBanGiao"))) entity.NgayBanGiao = reader.GetDateTime(reader.GetOrdinal("NgayBanGiao"));
				if (!reader.IsDBNull(reader.GetOrdinal("CanBoTheoDoi"))) entity.CanBoTheoDoi = reader.GetString(reader.GetOrdinal("CanBoTheoDoi"));
				if (!reader.IsDBNull(reader.GetOrdinal("TrangThai"))) entity.TrangThai = reader.GetString(reader.GetOrdinal("TrangThai"));
				if (!reader.IsDBNull(reader.GetOrdinal("GhiChu"))) entity.GhiChu = reader.GetString(reader.GetOrdinal("GhiChu"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBienBan"))) entity.SoBienBan = reader.GetString(reader.GetOrdinal("SoBienBan"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoVanTaiDon"))) entity.SoVanTaiDon = reader.GetString(reader.GetOrdinal("SoVanTaiDon"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanChinhToKhai"))) entity.SoBanChinhToKhai = reader.GetInt32(reader.GetOrdinal("SoBanChinhToKhai"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanChinhDonChuyenCuaKhau"))) entity.SoBanChinhDonChuyenCuaKhau = reader.GetInt32(reader.GetOrdinal("SoBanChinhDonChuyenCuaKhau"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanSaoVanTaiDon"))) entity.SoBanSaoVanTaiDon = reader.GetInt32(reader.GetOrdinal("SoBanSaoVanTaiDon"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoBanChinhBanKeChiTiet"))) entity.SoBanChinhBanKeChiTiet = reader.GetInt32(reader.GetOrdinal("SoBanChinhBanKeChiTiet"));
				if (!reader.IsDBNull(reader.GetOrdinal("MoTaHangHoa"))) entity.MoTaHangHoa = reader.GetString(reader.GetOrdinal("MoTaHangHoa"));
				if (!reader.IsDBNull(reader.GetOrdinal("TinhTrangHangHoa"))) entity.TinhTrangHangHoa = reader.GetString(reader.GetOrdinal("TinhTrangHangHoa"));
				if (!reader.IsDBNull(reader.GetOrdinal("BienBanVeTinhTrangHangHoa"))) entity.BienBanVeTinhTrangHangHoa = reader.GetString(reader.GetOrdinal("BienBanVeTinhTrangHangHoa"));
				if (!reader.IsDBNull(reader.GetOrdinal("TuyenDuongVanChuyen"))) entity.TuyenDuongVanChuyen = reader.GetString(reader.GetOrdinal("TuyenDuongVanChuyen"));
				if (!reader.IsDBNull(reader.GetOrdinal("ChieuDai"))) entity.ChieuDai = reader.GetDecimal(reader.GetOrdinal("ChieuDai"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThoiGianVanChuyen"))) entity.ThoiGianVanChuyen = reader.GetDecimal(reader.GetOrdinal("ThoiGianVanChuyen"));
				if (!reader.IsDBNull(reader.GetOrdinal("GioXuatPhat"))) entity.GioXuatPhat = reader.GetDateTime(reader.GetOrdinal("GioXuatPhat"));
				if (!reader.IsDBNull(reader.GetOrdinal("CacVanDeLienQuan"))) entity.CacVanDeLienQuan = reader.GetString(reader.GetOrdinal("CacVanDeLienQuan"));
				if (!reader.IsDBNull(reader.GetOrdinal("NguoiNhapDuLieu"))) entity.NguoiNhapDuLieu = reader.GetString(reader.GetOrdinal("NguoiNhapDuLieu"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayNhapDuLieu"))) entity.NgayNhapDuLieu = reader.GetDateTime(reader.GetOrdinal("NgayNhapDuLieu"));
				collection.Add(entity);
			}
			
			reader.Close();
			return collection;			
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		

		public static DataSet SelectAll()
        {
            const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_SelectAll]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			
            return db.ExecuteDataSet(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_SelectDynamic]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteDataSet(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
				
		public static IDataReader SelectReaderAll()
        {
            const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_SelectAll]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
            return db.ExecuteReader(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static IDataReader SelectReaderDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_SelectDynamic]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteReader(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert methods.
		
		public static int InsertBienBan(int soToKhai, string maHaiQuan, string maLoaiHinh, int namDangKy, string maDoanhNghiep, int phanLuong, int soTo, string truongHop, string maHaiQuanChuyenDen, string noiGiao, string nguoiGiao, string noiNhan, string nguoiNhan, DateTime ngayBanGiao, string canBoTheoDoi, string trangThai, string ghiChu, string soBienBan, string soVanTaiDon, int soBanChinhToKhai, int soBanChinhDonChuyenCuaKhau, int soBanSaoVanTaiDon, int soBanChinhBanKeChiTiet, string moTaHangHoa, string tinhTrangHangHoa, string bienBanVeTinhTrangHangHoa, string tuyenDuongVanChuyen, decimal chieuDai, decimal thoiGianVanChuyen, DateTime gioXuatPhat, string cacVanDeLienQuan, string nguoiNhapDuLieu, DateTime ngayNhapDuLieu)
		{
			BienBan entity = new BienBan();	
			entity.SoToKhai = soToKhai;
			entity.MaHaiQuan = maHaiQuan;
			entity.MaLoaiHinh = maLoaiHinh;
			entity.NamDangKy = namDangKy;
			entity.MaDoanhNghiep = maDoanhNghiep;
			entity.PhanLuong = phanLuong;
			entity.SoTo = soTo;
			entity.TruongHop = truongHop;
			entity.MaHaiQuanChuyenDen = maHaiQuanChuyenDen;
			entity.NoiGiao = noiGiao;
			entity.NguoiGiao = nguoiGiao;
			entity.NoiNhan = noiNhan;
			entity.NguoiNhan = nguoiNhan;
			entity.NgayBanGiao = ngayBanGiao;
			entity.CanBoTheoDoi = canBoTheoDoi;
			entity.TrangThai = trangThai;
			entity.GhiChu = ghiChu;
			entity.SoBienBan = soBienBan;
			entity.SoVanTaiDon = soVanTaiDon;
			entity.SoBanChinhToKhai = soBanChinhToKhai;
			entity.SoBanChinhDonChuyenCuaKhau = soBanChinhDonChuyenCuaKhau;
			entity.SoBanSaoVanTaiDon = soBanSaoVanTaiDon;
			entity.SoBanChinhBanKeChiTiet = soBanChinhBanKeChiTiet;
			entity.MoTaHangHoa = moTaHangHoa;
			entity.TinhTrangHangHoa = tinhTrangHangHoa;
			entity.BienBanVeTinhTrangHangHoa = bienBanVeTinhTrangHangHoa;
			entity.TuyenDuongVanChuyen = tuyenDuongVanChuyen;
			entity.ChieuDai = chieuDai;
			entity.ThoiGianVanChuyen = thoiGianVanChuyen;
			entity.GioXuatPhat = gioXuatPhat;
			entity.CacVanDeLienQuan = cacVanDeLienQuan;
			entity.NguoiNhapDuLieu = nguoiNhapDuLieu;
			entity.NgayNhapDuLieu = ngayNhapDuLieu;
			return entity.Insert();
		}
		
		public int Insert()
		{
			return this.Insert(null);
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public int Insert(SqlTransaction transaction)
		{			
			const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_Insert]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@SoToKhai", SqlDbType.Int, SoToKhai);
			db.AddInParameter(dbCommand, "@MaHaiQuan", SqlDbType.Char, MaHaiQuan);
			db.AddInParameter(dbCommand, "@MaLoaiHinh", SqlDbType.Char, MaLoaiHinh);
			db.AddInParameter(dbCommand, "@NamDangKy", SqlDbType.Int, NamDangKy);
			db.AddInParameter(dbCommand, "@MaDoanhNghiep", SqlDbType.VarChar, MaDoanhNghiep);
			db.AddInParameter(dbCommand, "@PhanLuong", SqlDbType.Int, PhanLuong);
			db.AddInParameter(dbCommand, "@SoTo", SqlDbType.Int, SoTo);
			db.AddInParameter(dbCommand, "@TruongHop", SqlDbType.Char, TruongHop);
			db.AddInParameter(dbCommand, "@MaHaiQuanChuyenDen", SqlDbType.Char, MaHaiQuanChuyenDen);
			db.AddInParameter(dbCommand, "@NoiGiao", SqlDbType.NVarChar, NoiGiao);
			db.AddInParameter(dbCommand, "@NguoiGiao", SqlDbType.NVarChar, NguoiGiao);
			db.AddInParameter(dbCommand, "@NoiNhan", SqlDbType.NVarChar, NoiNhan);
			db.AddInParameter(dbCommand, "@NguoiNhan", SqlDbType.NVarChar, NguoiNhan);
			db.AddInParameter(dbCommand, "@NgayBanGiao", SqlDbType.DateTime, NgayBanGiao.Year <= 1900 ? DBNull.Value : (object) NgayBanGiao);
			db.AddInParameter(dbCommand, "@CanBoTheoDoi", SqlDbType.VarChar, CanBoTheoDoi);
			db.AddInParameter(dbCommand, "@TrangThai", SqlDbType.VarChar, TrangThai);
			db.AddInParameter(dbCommand, "@GhiChu", SqlDbType.NVarChar, GhiChu);
			db.AddInParameter(dbCommand, "@SoBienBan", SqlDbType.NVarChar, SoBienBan);
			db.AddInParameter(dbCommand, "@SoVanTaiDon", SqlDbType.NVarChar, SoVanTaiDon);
			db.AddInParameter(dbCommand, "@SoBanChinhToKhai", SqlDbType.Int, SoBanChinhToKhai);
			db.AddInParameter(dbCommand, "@SoBanChinhDonChuyenCuaKhau", SqlDbType.Int, SoBanChinhDonChuyenCuaKhau);
			db.AddInParameter(dbCommand, "@SoBanSaoVanTaiDon", SqlDbType.Int, SoBanSaoVanTaiDon);
			db.AddInParameter(dbCommand, "@SoBanChinhBanKeChiTiet", SqlDbType.Int, SoBanChinhBanKeChiTiet);
			db.AddInParameter(dbCommand, "@MoTaHangHoa", SqlDbType.NVarChar, MoTaHangHoa);
			db.AddInParameter(dbCommand, "@TinhTrangHangHoa", SqlDbType.NVarChar, TinhTrangHangHoa);
			db.AddInParameter(dbCommand, "@BienBanVeTinhTrangHangHoa", SqlDbType.NVarChar, BienBanVeTinhTrangHangHoa);
			db.AddInParameter(dbCommand, "@TuyenDuongVanChuyen", SqlDbType.NVarChar, TuyenDuongVanChuyen);
			db.AddInParameter(dbCommand, "@ChieuDai", SqlDbType.Decimal, ChieuDai);
			db.AddInParameter(dbCommand, "@ThoiGianVanChuyen", SqlDbType.Decimal, ThoiGianVanChuyen);
			db.AddInParameter(dbCommand, "@GioXuatPhat", SqlDbType.DateTime, GioXuatPhat.Year <= 1900 ? DBNull.Value : (object) GioXuatPhat);
			db.AddInParameter(dbCommand, "@CacVanDeLienQuan", SqlDbType.NVarChar, CacVanDeLienQuan);
			db.AddInParameter(dbCommand, "@NguoiNhapDuLieu", SqlDbType.VarChar, NguoiNhapDuLieu);
			db.AddInParameter(dbCommand, "@NgayNhapDuLieu", SqlDbType.DateTime, NgayNhapDuLieu.Year <= 1900 ? DBNull.Value : (object) NgayNhapDuLieu);
			
			if (transaction != null)
			{
				return db.ExecuteNonQuery(dbCommand, transaction);
			}
            else
			{
				return db.ExecuteNonQuery(dbCommand);
			}			
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool InsertCollection(IList<BienBan> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using(SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (BienBan item in collection)
						{
							if (item.Insert(transaction) <= 0)
							{							
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert / Update methods.
		
		public static int InsertUpdateBienBan(int soToKhai, string maHaiQuan, string maLoaiHinh, int namDangKy, string maDoanhNghiep, int phanLuong, int soTo, string truongHop, string maHaiQuanChuyenDen, string noiGiao, string nguoiGiao, string noiNhan, string nguoiNhan, DateTime ngayBanGiao, string canBoTheoDoi, string trangThai, string ghiChu, string soBienBan, string soVanTaiDon, int soBanChinhToKhai, int soBanChinhDonChuyenCuaKhau, int soBanSaoVanTaiDon, int soBanChinhBanKeChiTiet, string moTaHangHoa, string tinhTrangHangHoa, string bienBanVeTinhTrangHangHoa, string tuyenDuongVanChuyen, decimal chieuDai, decimal thoiGianVanChuyen, DateTime gioXuatPhat, string cacVanDeLienQuan, string nguoiNhapDuLieu, DateTime ngayNhapDuLieu)
		{
			BienBan entity = new BienBan();			
			entity.SoToKhai = soToKhai;
			entity.MaHaiQuan = maHaiQuan;
			entity.MaLoaiHinh = maLoaiHinh;
			entity.NamDangKy = namDangKy;
			entity.MaDoanhNghiep = maDoanhNghiep;
			entity.PhanLuong = phanLuong;
			entity.SoTo = soTo;
			entity.TruongHop = truongHop;
			entity.MaHaiQuanChuyenDen = maHaiQuanChuyenDen;
			entity.NoiGiao = noiGiao;
			entity.NguoiGiao = nguoiGiao;
			entity.NoiNhan = noiNhan;
			entity.NguoiNhan = nguoiNhan;
			entity.NgayBanGiao = ngayBanGiao;
			entity.CanBoTheoDoi = canBoTheoDoi;
			entity.TrangThai = trangThai;
			entity.GhiChu = ghiChu;
			entity.SoBienBan = soBienBan;
			entity.SoVanTaiDon = soVanTaiDon;
			entity.SoBanChinhToKhai = soBanChinhToKhai;
			entity.SoBanChinhDonChuyenCuaKhau = soBanChinhDonChuyenCuaKhau;
			entity.SoBanSaoVanTaiDon = soBanSaoVanTaiDon;
			entity.SoBanChinhBanKeChiTiet = soBanChinhBanKeChiTiet;
			entity.MoTaHangHoa = moTaHangHoa;
			entity.TinhTrangHangHoa = tinhTrangHangHoa;
			entity.BienBanVeTinhTrangHangHoa = bienBanVeTinhTrangHangHoa;
			entity.TuyenDuongVanChuyen = tuyenDuongVanChuyen;
			entity.ChieuDai = chieuDai;
			entity.ThoiGianVanChuyen = thoiGianVanChuyen;
			entity.GioXuatPhat = gioXuatPhat;
			entity.CacVanDeLienQuan = cacVanDeLienQuan;
			entity.NguoiNhapDuLieu = nguoiNhapDuLieu;
			entity.NgayNhapDuLieu = ngayNhapDuLieu;
			return entity.InsertUpdate();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int InsertUpdate()
		{
			return this.InsertUpdate(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int InsertUpdate(SqlTransaction transaction)
		{			
			const string spName = "p_HAIQUAN_QLHS_BienBan_InsertUpdate";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@SoToKhai", SqlDbType.Int, SoToKhai);
			db.AddInParameter(dbCommand, "@MaHaiQuan", SqlDbType.Char, MaHaiQuan);
			db.AddInParameter(dbCommand, "@MaLoaiHinh", SqlDbType.Char, MaLoaiHinh);
			db.AddInParameter(dbCommand, "@NamDangKy", SqlDbType.Int, NamDangKy);
			db.AddInParameter(dbCommand, "@MaDoanhNghiep", SqlDbType.VarChar, MaDoanhNghiep);
			db.AddInParameter(dbCommand, "@PhanLuong", SqlDbType.Int, PhanLuong);
			db.AddInParameter(dbCommand, "@SoTo", SqlDbType.Int, SoTo);
			db.AddInParameter(dbCommand, "@TruongHop", SqlDbType.Char, TruongHop);
			db.AddInParameter(dbCommand, "@MaHaiQuanChuyenDen", SqlDbType.Char, MaHaiQuanChuyenDen);
			db.AddInParameter(dbCommand, "@NoiGiao", SqlDbType.NVarChar, NoiGiao);
			db.AddInParameter(dbCommand, "@NguoiGiao", SqlDbType.NVarChar, NguoiGiao);
			db.AddInParameter(dbCommand, "@NoiNhan", SqlDbType.NVarChar, NoiNhan);
			db.AddInParameter(dbCommand, "@NguoiNhan", SqlDbType.NVarChar, NguoiNhan);
			db.AddInParameter(dbCommand, "@NgayBanGiao", SqlDbType.DateTime, NgayBanGiao.Year == 1753 ? DBNull.Value : (object) NgayBanGiao);
			db.AddInParameter(dbCommand, "@CanBoTheoDoi", SqlDbType.VarChar, CanBoTheoDoi);
			db.AddInParameter(dbCommand, "@TrangThai", SqlDbType.VarChar, TrangThai);
			db.AddInParameter(dbCommand, "@GhiChu", SqlDbType.NVarChar, GhiChu);
			db.AddInParameter(dbCommand, "@SoBienBan", SqlDbType.NVarChar, SoBienBan);
			db.AddInParameter(dbCommand, "@SoVanTaiDon", SqlDbType.NVarChar, SoVanTaiDon);
			db.AddInParameter(dbCommand, "@SoBanChinhToKhai", SqlDbType.Int, SoBanChinhToKhai);
			db.AddInParameter(dbCommand, "@SoBanChinhDonChuyenCuaKhau", SqlDbType.Int, SoBanChinhDonChuyenCuaKhau);
			db.AddInParameter(dbCommand, "@SoBanSaoVanTaiDon", SqlDbType.Int, SoBanSaoVanTaiDon);
			db.AddInParameter(dbCommand, "@SoBanChinhBanKeChiTiet", SqlDbType.Int, SoBanChinhBanKeChiTiet);
			db.AddInParameter(dbCommand, "@MoTaHangHoa", SqlDbType.NVarChar, MoTaHangHoa);
			db.AddInParameter(dbCommand, "@TinhTrangHangHoa", SqlDbType.NVarChar, TinhTrangHangHoa);
			db.AddInParameter(dbCommand, "@BienBanVeTinhTrangHangHoa", SqlDbType.NVarChar, BienBanVeTinhTrangHangHoa);
			db.AddInParameter(dbCommand, "@TuyenDuongVanChuyen", SqlDbType.NVarChar, TuyenDuongVanChuyen);
			db.AddInParameter(dbCommand, "@ChieuDai", SqlDbType.Decimal, ChieuDai);
			db.AddInParameter(dbCommand, "@ThoiGianVanChuyen", SqlDbType.Decimal, ThoiGianVanChuyen);
			db.AddInParameter(dbCommand, "@GioXuatPhat", SqlDbType.DateTime, GioXuatPhat.Year == 1753 ? DBNull.Value : (object) GioXuatPhat);
			db.AddInParameter(dbCommand, "@CacVanDeLienQuan", SqlDbType.NVarChar, CacVanDeLienQuan);
			db.AddInParameter(dbCommand, "@NguoiNhapDuLieu", SqlDbType.VarChar, NguoiNhapDuLieu);
			db.AddInParameter(dbCommand, "@NgayNhapDuLieu", SqlDbType.DateTime, NgayNhapDuLieu.Year == 1753 ? DBNull.Value : (object) NgayNhapDuLieu);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);			
		}
		
		//---------------------------------------------------------------------------------------------
		public static bool InsertUpdateCollection(IList<BienBan> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (BienBan item in collection)
						{
							if (item.InsertUpdate(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertUpdateCollection method: " + ex.Message);
						
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}	
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Update methods.
		
		public static int UpdateBienBan(int soToKhai, string maHaiQuan, string maLoaiHinh, int namDangKy, string maDoanhNghiep, int phanLuong, int soTo, string truongHop, string maHaiQuanChuyenDen, string noiGiao, string nguoiGiao, string noiNhan, string nguoiNhan, DateTime ngayBanGiao, string canBoTheoDoi, string trangThai, string ghiChu, string soBienBan, string soVanTaiDon, int soBanChinhToKhai, int soBanChinhDonChuyenCuaKhau, int soBanSaoVanTaiDon, int soBanChinhBanKeChiTiet, string moTaHangHoa, string tinhTrangHangHoa, string bienBanVeTinhTrangHangHoa, string tuyenDuongVanChuyen, decimal chieuDai, decimal thoiGianVanChuyen, DateTime gioXuatPhat, string cacVanDeLienQuan, string nguoiNhapDuLieu, DateTime ngayNhapDuLieu)
		{
			BienBan entity = new BienBan();			
			entity.SoToKhai = soToKhai;
			entity.MaHaiQuan = maHaiQuan;
			entity.MaLoaiHinh = maLoaiHinh;
			entity.NamDangKy = namDangKy;
			entity.MaDoanhNghiep = maDoanhNghiep;
			entity.PhanLuong = phanLuong;
			entity.SoTo = soTo;
			entity.TruongHop = truongHop;
			entity.MaHaiQuanChuyenDen = maHaiQuanChuyenDen;
			entity.NoiGiao = noiGiao;
			entity.NguoiGiao = nguoiGiao;
			entity.NoiNhan = noiNhan;
			entity.NguoiNhan = nguoiNhan;
			entity.NgayBanGiao = ngayBanGiao;
			entity.CanBoTheoDoi = canBoTheoDoi;
			entity.TrangThai = trangThai;
			entity.GhiChu = ghiChu;
			entity.SoBienBan = soBienBan;
			entity.SoVanTaiDon = soVanTaiDon;
			entity.SoBanChinhToKhai = soBanChinhToKhai;
			entity.SoBanChinhDonChuyenCuaKhau = soBanChinhDonChuyenCuaKhau;
			entity.SoBanSaoVanTaiDon = soBanSaoVanTaiDon;
			entity.SoBanChinhBanKeChiTiet = soBanChinhBanKeChiTiet;
			entity.MoTaHangHoa = moTaHangHoa;
			entity.TinhTrangHangHoa = tinhTrangHangHoa;
			entity.BienBanVeTinhTrangHangHoa = bienBanVeTinhTrangHangHoa;
			entity.TuyenDuongVanChuyen = tuyenDuongVanChuyen;
			entity.ChieuDai = chieuDai;
			entity.ThoiGianVanChuyen = thoiGianVanChuyen;
			entity.GioXuatPhat = gioXuatPhat;
			entity.CacVanDeLienQuan = cacVanDeLienQuan;
			entity.NguoiNhapDuLieu = nguoiNhapDuLieu;
			entity.NgayNhapDuLieu = ngayNhapDuLieu;
			return entity.Update();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int Update()
		{
			return this.Update(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Update(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_Update]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@SoToKhai", SqlDbType.Int, SoToKhai);
			db.AddInParameter(dbCommand, "@MaHaiQuan", SqlDbType.Char, MaHaiQuan);
			db.AddInParameter(dbCommand, "@MaLoaiHinh", SqlDbType.Char, MaLoaiHinh);
			db.AddInParameter(dbCommand, "@NamDangKy", SqlDbType.Int, NamDangKy);
			db.AddInParameter(dbCommand, "@MaDoanhNghiep", SqlDbType.VarChar, MaDoanhNghiep);
			db.AddInParameter(dbCommand, "@PhanLuong", SqlDbType.Int, PhanLuong);
			db.AddInParameter(dbCommand, "@SoTo", SqlDbType.Int, SoTo);
			db.AddInParameter(dbCommand, "@TruongHop", SqlDbType.Char, TruongHop);
			db.AddInParameter(dbCommand, "@MaHaiQuanChuyenDen", SqlDbType.Char, MaHaiQuanChuyenDen);
			db.AddInParameter(dbCommand, "@NoiGiao", SqlDbType.NVarChar, NoiGiao);
			db.AddInParameter(dbCommand, "@NguoiGiao", SqlDbType.NVarChar, NguoiGiao);
			db.AddInParameter(dbCommand, "@NoiNhan", SqlDbType.NVarChar, NoiNhan);
			db.AddInParameter(dbCommand, "@NguoiNhan", SqlDbType.NVarChar, NguoiNhan);
			db.AddInParameter(dbCommand, "@NgayBanGiao", SqlDbType.DateTime, NgayBanGiao.Year == 1753 ? DBNull.Value : (object) NgayBanGiao);
			db.AddInParameter(dbCommand, "@CanBoTheoDoi", SqlDbType.VarChar, CanBoTheoDoi);
			db.AddInParameter(dbCommand, "@TrangThai", SqlDbType.VarChar, TrangThai);
			db.AddInParameter(dbCommand, "@GhiChu", SqlDbType.NVarChar, GhiChu);
			db.AddInParameter(dbCommand, "@SoBienBan", SqlDbType.NVarChar, SoBienBan);
			db.AddInParameter(dbCommand, "@SoVanTaiDon", SqlDbType.NVarChar, SoVanTaiDon);
			db.AddInParameter(dbCommand, "@SoBanChinhToKhai", SqlDbType.Int, SoBanChinhToKhai);
			db.AddInParameter(dbCommand, "@SoBanChinhDonChuyenCuaKhau", SqlDbType.Int, SoBanChinhDonChuyenCuaKhau);
			db.AddInParameter(dbCommand, "@SoBanSaoVanTaiDon", SqlDbType.Int, SoBanSaoVanTaiDon);
			db.AddInParameter(dbCommand, "@SoBanChinhBanKeChiTiet", SqlDbType.Int, SoBanChinhBanKeChiTiet);
			db.AddInParameter(dbCommand, "@MoTaHangHoa", SqlDbType.NVarChar, MoTaHangHoa);
			db.AddInParameter(dbCommand, "@TinhTrangHangHoa", SqlDbType.NVarChar, TinhTrangHangHoa);
			db.AddInParameter(dbCommand, "@BienBanVeTinhTrangHangHoa", SqlDbType.NVarChar, BienBanVeTinhTrangHangHoa);
			db.AddInParameter(dbCommand, "@TuyenDuongVanChuyen", SqlDbType.NVarChar, TuyenDuongVanChuyen);
			db.AddInParameter(dbCommand, "@ChieuDai", SqlDbType.Decimal, ChieuDai);
			db.AddInParameter(dbCommand, "@ThoiGianVanChuyen", SqlDbType.Decimal, ThoiGianVanChuyen);
			db.AddInParameter(dbCommand, "@GioXuatPhat", SqlDbType.DateTime, GioXuatPhat.Year == 1753 ? DBNull.Value : (object) GioXuatPhat);
			db.AddInParameter(dbCommand, "@CacVanDeLienQuan", SqlDbType.NVarChar, CacVanDeLienQuan);
			db.AddInParameter(dbCommand, "@NguoiNhapDuLieu", SqlDbType.VarChar, NguoiNhapDuLieu);
			db.AddInParameter(dbCommand, "@NgayNhapDuLieu", SqlDbType.DateTime, NgayNhapDuLieu.Year == 1753 ? DBNull.Value : (object) NgayNhapDuLieu);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool UpdateCollection(IList<BienBan> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (BienBan item in collection)
						{
							if (item.Update(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at UpdateCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Delete methods.
		
		public static int DeleteBienBan(int soToKhai, string maHaiQuan, string maLoaiHinh, int namDangKy)
		{
			BienBan entity = new BienBan();
			entity.SoToKhai = soToKhai;
			entity.MaHaiQuan = maHaiQuan;
			entity.MaLoaiHinh = maLoaiHinh;
			entity.NamDangKy = namDangKy;
			return entity.Delete();
		}
		
		public int Delete()
		{
			return this.Delete(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Delete(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_Delete]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@SoToKhai", SqlDbType.Int, SoToKhai);
			db.AddInParameter(dbCommand, "@MaHaiQuan", SqlDbType.Char, MaHaiQuan);
			db.AddInParameter(dbCommand, "@MaLoaiHinh", SqlDbType.Char, MaLoaiHinh);
			db.AddInParameter(dbCommand, "@NamDangKy", SqlDbType.Int, NamDangKy);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
		public static bool DeleteCollection(IList<BienBan> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (BienBan item in collection)
						{
							if (item.Delete(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at DeleteCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		#endregion
	}	
}